import { createRouter, createWebHistory } from "vue-router";
import Login from "@/views/login/index.vue";
import Layout from "@/Layout/index.vue";
import { dynamicRoutes } from "./dynamic-router";

// 静态路由
export const constantRoutes = [
  {
    path: "/",
    component: Layout,
    redirect: "/home",
    children: [
      {
        path: "home",
        name: "home",
        component: () => import("@/views/home/index.vue"),
        meta: { title: "首页", hidden: false, icon: "DataLine" }, // hidden为true式，可在layout页面设置为隐藏菜单
      },

      // 在此添加更多的动态子路由
    ],
  },
  {
    path: "/login",
    name: "login",
    component: Login,
  },

  {
    path: "/:pathMatch(.*)*", //通配符路由，匹配所有其他无效路径
    name: "404",
    component: () => import("@/views/error/404.vue"),
  },
  // {
  //   path: '/403',
  //   name: '403',
  //   component: () => import('../views/error-page/403.vue')
  // }
];

// 添加动态路由
constantRoutes
  .find((item) => item.path === "/")
  .children.push(...dynamicRoutes);

const router = createRouter({
  history: createWebHistory(),
  routes: constantRoutes,
});

export default router;
